package cn.edu.ecnu.gis.client.gadgets;

import cn.edu.ecnu.gis.client.MashupGISEntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

import cn.edu.ecnu.gis.client.Th3CallService;
import cn.edu.ecnu.gis.client.Th3CallServiceAsync;
import cn.edu.ecnu.gis.client.model.Gadget;
import cn.edu.ecnu.gis.client.model.GadgetClass;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.ImageBundle;
import com.google.gwt.user.client.ui.Label;

public class RouteLayer extends Gadget {

    public static class Class extends GadgetClass {

        public Class() {
            super("路径分析", false);
            this.setGadgetType(2);
        }

        public Gadget newGadget() {
            return new RouteLayer(this);
        }
    }
    private VerticalPanel vp = new VerticalPanel();
    private TextBox wsreturn = new TextBox();
    Button jumpBtn = new Button("分析", new ClickListener() {

        public void onClick(Widget sender) {
            try {
                GoogleMapsGadget googleMapsGadget = (GoogleMapsGadget) MashupGISEntryPoint.widgetsList.get("Google Map");
                // GadgetClass gadgetClass1 = (GadgetClass) GadgetClass.getClasses().get(3);
                //GoogleMapsGadget googleMapsGadget=(GoogleMapsGadget)gadgetClass1;
                //double lon = Double.parseDouble(Lattb.getText());
                //double lan = Double.parseDouble(Lontb.getText());

                googleMapsGadget.getGMap().addGeoXML("http://meflyup.googlepages.com/routkml.kmz");
                googleMapsGadget.getGMap().setCenter(37.75722, -122.44722);
            // getService().myMethod(wsreturn.getText(), callback);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        // GoogleMapsGadget googleMapsGadget = (GoogleMapsGadget) GadgetClass.getClasses().get(3);

        }
    });

    protected RouteLayer(Class c) {
        super(c);
        initWidget(vp);

        CheckBox stopsCheckBox1 = new CheckBox("GIRARD MEDICAL CENTER");
        CheckBox stopsCheckBox2 = new CheckBox("UC SAN FRANCISCO MEDICAL CENTER");
        CheckBox stopsCheckBox3 = new CheckBox("COUTURE MEDICAL CENTER");
        CheckBox stopsCheckBox4 = new CheckBox("ST LUKE'S HOSPITAL");
        CheckBox stopsCheckBox5 = new CheckBox("DAVIES MEDICAL CENTER");
        CheckBox stopsCheckBox6 = new CheckBox("ST LUKE'S HOSPITAL");
        CheckBox stopsCheckBox7 = new CheckBox("Walters Office Building");
        CheckBox stopsCheckBox8 = new CheckBox("ST FRANCIS MEMORIAL HOSPITAL");
        CheckBox stopsCheckBox9 = new CheckBox("CHINESE HOSPITAL");
        CheckBox stopsCheckBox10 = new CheckBox("SAN FRANCISCO GENERAL HOSPITAL");
        vp.add(new Label("选择要参与路径分析的停靠点"));
        vp.add(stopsCheckBox1);
        vp.add(stopsCheckBox2);
        vp.add(stopsCheckBox3);
        vp.add(stopsCheckBox4);
        vp.add(stopsCheckBox5);
        vp.add(stopsCheckBox6);
        vp.add(stopsCheckBox7);
        vp.add(stopsCheckBox8);
        vp.add(stopsCheckBox9);
        vp.add(stopsCheckBox10);
        vp.add(jumpBtn);

        //vp.add(wsreturn);
        vp.setWidth("100%");
    // Create an asynchronous callback to handle the result.

    }
    final AsyncCallback callback = new  

          AsyncCallback( ) {

             
        

        public  void onSuccess(Object result) {
            wsreturn.setText((String) result);
        }

        public void onFailure(Throwable caught) {
            wsreturn.setText("Communication failed");
        }
    };

    public static Th3CallServiceAsync getService() {
        // Create the client proxy. Note that although you are creating the
        // service interface proper, you cast the result to the asynchronous
        // version of
        // the interface. The cast is always safe because the generated proxy
        // implements the asynchronous interface automatically.
        Th3CallServiceAsync service = (Th3CallServiceAsync) GWT.create(Th3CallService.class);
        // Specify the URL at which our service implementation is running.
        // Note that the target URL must reside on the same domain and port from
        // which the host page was served.
        //
        ServiceDefTarget endpoint = (ServiceDefTarget) service;
        String moduleRelativeURL = GWT.getModuleBaseURL() + "th3callservice";
        endpoint.setServiceEntryPoint(moduleRelativeURL);
        return service;
    }

    public interface BoundImage extends ImageBundle {

        AbstractImagePrototype inbox();
    }

    public AbstractImagePrototype getBoundImage() {
        BoundImage images = (BoundImage) GWT.create(BoundImage.class);
        return images.inbox();
    }
}
